<?php
/**
 * Chat message class
 * 
 * @package stanza.message
 */
class Zend_Jabber_Stanza_Request_Message_Chat extends Zend_Jabber_Stanza_Request_Message_Abstract  {
    /**
     * Create new chat message object
     * 
     * @param Zend_Jabber_User $toUser Send message to this user
     * @param string $message Message body
     * @param string $subject Message subject. This parameter is optional
     */
    public function __construct(Zend_Jabber_User $toUser, $message, $subject = false) {       
       parent::__construct($toUser);
        
        $body = $this->dom->createElement('body', $message);
        $this->messageNode->appendChild($body);
        
        if($subject === false) {
            $subject = $this->dom->createElement('subject', $subject);
            $this->messageNode->appendChild($subject);
        }

        $events = array(
            self::EVENT_COMPOSING, 
            self::EVENT_DELIVERED,
            self::EVENT_OFFLINE,
            self::EVENT_DISPLAYED
        );
        
        if(!empty($events)) {
	        $x = $this->dom->createElement('x');
	        $x->setAttribute('xmlns', Zend_Jabber_Connection::NS_EVENT);
        
	        foreach($events as $event) {
		        $eventNote = $this->dom->createElement($event);
		        $x->appendChild($eventNote);
	        }
	        
	         $this->messageNode->appendChild($x);
        }
    }

}
?>
